package com.woniuxy.happylife.suggest.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.happylife.entity.Business;
import com.woniuxy.happylife.entity.ResponseEntity;
import com.woniuxy.happylife.suggest.service.PlatformService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author Fu
 * @Date 2022-02-23 10:00
 */
@RestController
@Slf4j
@CrossOrigin
@RequestMapping("platform")
public class PlatformController {
    @Resource
    PlatformService platformService;
    @GetMapping("findAll/{page}/{limit}")
    public ResponseEntity findAll(@PathVariable("page") int page,
                                  @PathVariable("limit") int limit){
        PageHelper.startPage(page,limit);
        List<Business> list=platformService.findAll();
        if(list.size()>0){
            PageInfo<Business> pageInfo = new PageInfo<>(list);
            return new ResponseEntity(200,"查询成功",pageInfo);
        }
        return new ResponseEntity(400,"查询失败",null);
    }

    @PostMapping ("update")
    public ResponseEntity update(@RequestBody Business business){
       int i =  platformService.update(business);
       if(i>0){
           return new ResponseEntity(200,"保存成功",null);
       }
       return new ResponseEntity(400,"失败",null);
    }
}
